﻿using Light.Framework.Model;
using Light.Utility;

namespace Light.Framework.Component
{
    /// <summary>
    /// 日志辅助类
    /// </summary>
    public class Logger
    {
        /// <summary>
        /// 记录错误日志
        /// </summary>
        /// <param name="msg"></param>
        public void LogError(string msg)
        {
            Log(msg, LogType.Error);
        }
        /// <summary>
        /// 记录登录日志
        /// </summary>
        /// <param name="msg"></param>
        public void LogLogin(string msg)
        {
            if (WebHelper.CurContext != null)
            {
                msg += string.Format(" 设备：{0}  IP：{1} UA：{2} ", 
                    WebHelper.GetDevice(), WebHelper.CurContext.Request.UserHostAddress, WebHelper.CurContext.Request.UserAgent);
            }
            Log(msg, LogType.Login);
        }
        /// <summary>
        /// 记录操作日志
        /// </summary>
        /// <param name="msg"></param>
        public void LogOperation(string msg)
        {
            Log(msg, LogType.Operation);
        }


        /// <summary>
        /// 记录访问日志
        /// </summary>
        /// <param name="msg"></param>
        public void LogVisited(string msg)
        {
            Log(msg, LogType.Visited);
        }

        /// <summary>
        /// 记录指定类型的日志
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="type"></param>
        public void Log(string msg, LogType type)
        {
            Log log = new Log();

            log.Content = msg;
            log.LogType = type;
            //EntityMediator<Log>.Create(log);
        }

    }
}
